<template>
	<view class="layout pageBg">
		<common-nav-bar>
			<template #title>首页</template>
		</common-nav-bar>
		<view class="banner">
			<swiper indicator-dots indicator-color="rgba(255,255,255,0.08)" indicator-active-color="#fff" autoplay interval="3000" circular>
				<swiper-item v-for="item in bannerList" :key="item._id">
					<image :src="item.picurl" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="26"></uni-icons>
				<text class="text">公告</text>
			</view>
			<view class="middle">
				<swiper :indicator-dots="false" autoplay :interval="5000" :duration="1000" circular vertical>
					<swiper-item v-for="item in notice" :key="item._id" >
						{{item.title}}
					</swiper-item>

				</swiper>
			</view>
			<view class="right">
				<uni-icons type="right" size="18" color="#333"></uni-icons>
			</view>
		</view>
		<view class="select">
			<common-title>
				<template #name>每日推荐</template>
				<template #custom>
					<view class="date">
						<uni-icons type="calendar" size="18"></uni-icons>
						<uni-dateformat :date="Date.now()" format="dd号"></uni-dateformat>
					</view>
				</template>
			</common-title>
			<div class="content">
				<scroll-view scroll-x>
					<view class="box" v-for="item in randowWall" :key="item._id" @click="goPreview">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</div>
		</view>
		<view class="theme">
			<common-title>
				<template #name>专题精选</template>
				<template #custom>
					<navigator url="" class="more">More+</navigator>
				</template>
			</common-title>
			<view class="content">
				<theme-item v-for="item in 8" :key="item"></theme-item>
				<theme-item :is-more="true"></theme-item>
			</view>
		</view>
	</view>
</template>

<script setup>
import {onLoad} from '@dcloudio/uni-app'
import { getBanner, getRandomWall, getNotice } from '../../api/api';
import { ref } from 'vue';
const bannerList = ref([]);
const randowWall = ref([]);
const notice = ref([]);
const getBannerList = async() => {
	let data = await getBanner()
	bannerList.value = data.data;
}
const getRandomWallList = async() => {
	let data = await getRandomWall()	
	randowWall.value = data.data;
	
}
const getNoticeList = async() => {
	let data = await getNotice({select: true})
	notice.value = data.data;
}

const goPreview = ()=> {
	uni.navigateTo({
		url: "/pages/preview/preview"
	})
}
onLoad(() =>{
	getBannerList();
	getRandomWallList();
	getNoticeList();
})
</script>

<style lang="scss" scoped>
.layout {
	.banner {
		width: 750rpx;
		padding: 30rpx 0;
		swiper {
			width: 750rpx;
			height: 340rpx;
			&-item {
				width: 100%;
				height: 100%;
				padding: 0 30rpx;
				image {
					width: 100%;
					height: 100%;
					border-radius: 12rpx;
				}
			}
		}
	}
	.notice {
		width: 690rpx;
		height: 80rpx;
		line-height: 80rpx;
		background: #f9f9f9;
		border-radius: 12rpx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		.left {
			width: 130rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			.text {
				color: $brand-theme-color;
				font-size: 28rpx;
				font-weight: 600;
			}
			:deep() {
				.uni-icons {
					color: $brand-theme-color !important;
				}
			}
		}
		.middle {
			flex: 1;
			height: 100%;
			swiper {
				height: 100%;
				swiper-item {
					font-size: 30rpx !important;
					color: #666;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}
		}
		.right {
			width: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.select {
		padding-top: 50rpx;
		.content {
			width: 720rpx;
			margin-left: 30rpx;
			margin-top: 30rpx;
			scroll-view {
				white-space: nowrap;
				.box {
					width: 200rpx;
					height: 430rpx;
					display: inline-block;
					margin-right: 15rpx;
					image {
						width: 100%;
						height: 100%;
						border-radius: 12rpx;
					}
					&:last-child {
						margin-right: 30rpx;
					}
				}
			}
		}
		.date {
			color: $brand-theme-color;
			display: flex;
			align-items: center;
			text {
				margin-left: 5rpx;
			}
			:deep() {
				.uni-icons {
					color: $brand-theme-color !important;
				}
			}
		}
	}
	.theme {
		padding: 50rpx 0;
		.more {
			font-size: 32rpx;
			color: #666;
		}
		.content {
			margin-top: 30rpx;
			padding: 0 30rpx;
			display: grid;
			gap: 15rpx;
			grid-template-columns: repeat(3,1fr)
		}
	}
}
</style>
